<template>
	<view>
		<view class="bg-white">
			<u-tabs @click="clickTab" scrollable :list="list1" lineWidth="30" lineColor="#3389FF" :activeStyle="{
			            color: '#3389FF',
			            fontWeight: 'bold',
			            transform: 'scale(1.05)'
			        }" :inactiveStyle="{
			            color: '#606266',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 18px; padding-right: 18px; height: 34px;">
			</u-tabs>
		</view>
		<view class="padding">
			<approveList v-if="entryStatus==2||entryStatus==3" :listData='siftList' :entryStatus="entryStatus">
			</approveList>
			<completeList v-else :listData='siftList' :entryStatus="entryStatus"></completeList>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-loadmore v-show="siftList.length>0" :status="status" />
	</view>
</template>

<script>
	import {
		listProjectInfo,
		listApproveProject
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				paramsObj: {
					2: 'projectApprove',
					3: 'projectBuild',
					4: 'projectCompletion',
					5: 'projectProduction',
					6: 'projectEfficiency'
				},
				entryStatus: null,
				policyForm: {
					pageNum: 1,
					pageSize: 10,
					state: 0
				},
				list1: [{
					name: '全部',
					state: null
				}, {
					name: '未填报',
					state: -1
				}, {
					name: '待审核',
					state: 1
				}, {
					name: '已通过',
					state: 0
				}, {
					name: '已退回',
					state: 2
				}],
				status: 'nomore',
				total: 0,
				dataList: [],
				scrollTop: 0,
				currentState: null,
				siftList: []
			}
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: option.title
			});
			this.policyForm.entryStatus = this.entryStatus = parseInt(option.entryStatus)
		},
		onShow() {
			this.search()
		},
		onReachBottom() {
			if (this.policyForm.pageNum >= this.total / 10) {
				this.status = 'nomore'
				return
			} else {
				this.status = 'loading'
				this.policyForm.pageNum++
				this.init()
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				});
				if (this.entryStatus == 2 || this.entryStatus == 3) {
					listApproveProject(this.policyForm).then(response => {
						if (response.code == 200) {
							uni.hideLoading();
							this.dataList = [...this.dataList, ...response.rows]
							if (this.currentState != null) {
								this.siftList = this.dataList.filter(item => item[this.paramsObj[this
										.entryStatus]] == this
									.currentState)
							} else {
								this.siftList = this.dataList
							}
							this.total = response.total
						} else {
							uni.hideLoading();
							uni.showToast({
								title: response.msg,
								icon: 'none',
								duration: 3000
							})
						}
						this.status = 'nomore'
					});
				} else {
					listProjectInfo(this.policyForm).then(response => {
						if (response.code == 200) {
							uni.hideLoading();
							this.dataList = [...this.dataList, ...response.rows]
							if (this.currentState != null) {
								this.siftList = this.dataList.filter(item => item[this.paramsObj[this
										.entryStatus]] == this
									.currentState)
							} else {
								this.siftList = this.dataList
							}
							this.total = response.total
						} else {
							uni.hideLoading();
							uni.showToast({
								title: response.msg,
								icon: 'none',
								duration: 3000
							})
						}
						this.status = 'nomore'
					});
				}
			},
			clickTab(item) {
				this.currentState = item.state
				this.policyForm.pageNum = 1
				this.dataList = []
				this.siftList = []
				this.init()
			},
			search() {
				this.policyForm.pageNum = 1
				this.dataList = []
				this.siftList = []
				this.init()
			}
		}
	}
</script>
<style>
</style>